const path = require('path');
const { paths } = require('../../utils');
const _ = require('lodash');

let webpackConfig = false;
let webpackDevConfig = false;
let webpackPrdConfig = false;
let webpackDllConfig = false;
let webpackDevServerConfig = false;
let webpackDevServerHotConfig = false;

let defaultWebpackConfig = {
  entry: {
    'common/common': 'common/index.js',
    'pages/*': 'pages/*/index.js'
  },
  output: {
    crossOriginLoading: "anonymous",
  },
  devtool: 'none',
  sendSourceMap: true,
  lessLoaderOptions: {},
  esLint: true,
  dll: {
    lib: ['react', 'react-dom', 'react-router-dom', 'mobx', 'mobx-react', 'axios', 'classnames']
  },
  plugins: [],
  extensions: ['.js', '.jsx', '.ts'],
  alias: {
    '@components': 'components',
    '@views': 'views',
    '@static': 'static',
    '@common': 'common',
  },
  devServer: {
    defaultBrowser: 'Google Chrome',
    host: '',
    feHost: '',
    port: '3000',
    proxy: {},
  },
  pages: []
}

try {
  webpackConfig = _.assignIn({}, defaultWebpackConfig, require(path.join(paths.roots, 'webpack.config')));
} catch (e) {
  webpackConfig = defaultWebpackConfig;
}

try {
  webpackDevConfig = require(path.join(paths.roots, 'webpack.dev.config'));
} catch (e) {
  webpackDevConfig = false;
}

try {
  webpackPrdConfig = require(path.join(paths.roots, 'webpack.prd.config'));
} catch (e) {
  webpackPrdConfig = false;
}

try {
  webpackDllConfig = require(path.join(paths.roots, 'webpack.dll.config'));
} catch (e) {
  webpackDllConfig = false;
}

try {
  webpackDevServerConfig = require(path.join(paths.roots, 'webpack.devServer.config'));
} catch (e) {
  webpackDevServerConfig = false;
}

try {
  webpackDevServerHotConfig = require(path.join(paths.roots, 'webpack.devServerHot.config'));
} catch (e) {
  webpackDevServerHotConfig = false;
}

module.exports = {
  webpackConfig,
  webpackDevConfig,
  webpackPrdConfig,
  webpackDllConfig,
  webpackDevServerConfig,
  webpackDevServerHotConfig
}



